"""
34 - Dars BeautifulSoup
"""
from bs4 import BeautifulSoup
import urllib.request

REQ = urllib.request.urlopen('https://kun.uz/')
HTML = REQ.read()
soup = BeautifulSoup(HTML)
print(soup)



SOUPP = Beautifulsoup(HTML, 'html.parser')
NEWS = SOUPP.find_all('div', class_="col-md-6")
print(NEWS)

RESULTS = []

for item in NEWS:
    title = item.find('div', class_='col-md-6')
    desc = item.find('div', class_='row')
    href = item.find('a', 'href')
    RESULTS.append({
        'title': title,
        'desc': desc,
        'href': href,
    })
print(RESULTS)

F = open('news.txt', 'w', encoding='utf-8')
i = 1
for item in RESULTS:
    F.write(f'Ноост {i}\n\nНазни: {item["ti"]}\nОписани: {item["de"]}\nСсылк: {item["hr"]}\n\n*\n')
    i += 1
F.close()
